package com.pearadmin.modules.sys.controller.work;

import com.github.pagehelper.PageInfo;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import com.pearadmin.modules.sys.domain.WorkFixDetail;
import com.pearadmin.modules.sys.service.IWorkFixDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 维修类型详情Controller
 *
 * @author Mr.Ling
 * @date 2021-12-17
 */
@RestController
@RequestMapping("/work/fixDetail")
public class WorkFixDetailController extends BaseController {

    private String prefix = "work/fixDetail";

    @Autowired
    private IWorkFixDetailService workFixDetailService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/work/fixDetail/main','work:fixDetail:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询维修类型详情列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/work/fixDetail/data','work:fixDetail:data')")
    public ResultTable list(@ModelAttribute WorkFixDetail workFixDetail, PageDomain pageDomain) {
        PageInfo<WorkFixDetail> pageInfo = workFixDetailService.selectWorkFixDetailPage(workFixDetail, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增维修类型详情
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/work/fixDetail/add','work:fixDetail:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存维修类型详情
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/work/fixDetail/add','work:fixDetail:add')")
    public Result save(@RequestBody WorkFixDetail workFixDetail) {
        return decide(workFixDetailService.insertWorkFixDetail(workFixDetail));
    }

    /**
     * 修改维修类型详情
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/work/fixDetail/edit','work:fixDetail:edit')")
    public ModelAndView edit(String id, ModelMap mmap) {
        WorkFixDetail workFixDetail =workFixDetailService.selectWorkFixDetailById(id);
        mmap.put("workFixDetail", workFixDetail);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存维修类型详情
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/work/fixDetail/edit','work:fixDetail:edit')")
    public Result update(@RequestBody WorkFixDetail workFixDetail) {
        return decide(workFixDetailService.updateWorkFixDetail(workFixDetail));
    }

    /**
     * 删除维修类型详情
     */
    @ResponseBody
    @DeleteMapping("/batchRemove")
    @PreAuthorize("hasPermission('/work/fixDetail/remove','work:fixDetail:remove')")
    public Result batchRemove(String ids) {
        return decide(workFixDetailService.deleteWorkFixDetailByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/work/fixDetail/remove','work:fixDetail:remove')")
    public Result remove(@PathVariable("id") String id) {
        return decide(workFixDetailService.deleteWorkFixDetailById(id));
    }
}
